package cc.realxyq.demo.config;

import cc.realxyq.demo.bean.ColorFactoryBean;
import cc.realxyq.demo.bean.Red;
import cc.realxyq.demo.component.MyBeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @author kwhan
 * @date 2022年01月07日 18:14
 */
@Configuration
//@Import({MyBeanPostProcessor.class, MyImportSelector.class, MyImportBeanDefinitionRegistrar.class})
@Import({MyBeanPostProcessor.class})

public class ImportConfig {

    /**
     *  当注入的bean是FactoryBean的时候， 直接从容器中取，是会获得工厂bean.getObject()方法范围的bean
     *  如果想获得 FactoryBean的对象本身 用 &beanName 取，原因查看 BeanFactory 接口
     * @return 返回工厂bean的getObject方法范围的对象
     */
    @Bean
    public ColorFactoryBean colorFactoryBean(){
        return new ColorFactoryBean();
    }

    @Bean(initMethod = "init",destroyMethod = "destroy1")
    public Red red(){
        return  new Red("通过@Bean 注入的");
    }
}
